package com.hdaccp.cn.card;

import java.io.IOException;
import java.util.Random;

import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

/**
 * 生成100副扑克，并随机缺少一张
 * @author hduser
 *
 */
public class CardGenerator {
	private static int n=100;//共100副	
	private static String[] style={"A","B","C","D"};//花色
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		//生成随机缺少的牌		
		Random r=new Random();
		int missed=r.nextInt(5200);
        System.out.println("missed= " + missed);
		
		Configuration conf = new Configuration();		
		FileSystem fs = FileSystem.get(conf);
		int m=0;
		//
		for(int k=0;k<100;k++){
			Path f=new Path("/input4/ch06/cards"+k);
			FSDataOutputStream outputStream=fs.create(f);		
			
			for(int i=1;i<=13;i++){
				for(int j=0;j<4;j++)
				{
					if(m!=missed)//随机少生成一张
					{
						IOUtils.write(i + "\t" +style[j]+"\n", outputStream);
						//System.out.println(i + "\t" +style[j]);
					}
					else{
                        System.out.println("m= " + m + "missed= " + missed);
                        System.out.println("k=" + k + " i=" + i + " j=" + j);
                    }
					m++;
				}
			}

			outputStream.close();
		}

		
	}

}
